﻿using Microsoft.Extensions.DependencyInjection;
using Sora.Sharding.EntityFramework.Core;

namespace Sora.Sharding.Application
{
    public interface IDemo1EntityService
    {
        /// <summary>
        /// 新增一条
        /// </summary>
        /// <param name = "input" ></param >
        /// <returns ></returns >
         Task CreateNowAsync(Demo1Entity input);
    }


    /// <summary>
    /// 
    /// </summary>
    public class Demo1EntityService : IDemo1EntityService, ITransient
    {
        /// <summary>
        /// 泛型仓储
        /// </summary>
        public readonly IRepository<Demo1Entity, MasterDbContextLocator> _repository;

        /// <summary>
        /// 
        /// </summary>
        public Demo1EntityService(IRepository<Demo1Entity, MasterDbContextLocator> repository)
        {
            _repository = repository;
        }

        /// <summary>
        /// 新增一条
        /// </summary>
        /// <param name = "input" ></param >
        /// <returns ></returns >
        public virtual async Task CreateNowAsync(Demo1Entity input)
        {
            var (rep, scoped) = _repository.BuildChange<Demo1Entity>();
            await rep.InsertNowAsync(input);
            scoped.Dispose();
        }
    }
}
